<?php

$app = new \Phalcon\Mvc\Micro();
//设置404
$app->notFound(function()use($app){
    $app->response->setStatusCode(404, 'Not Found')->sendHeaders();
    echo 'This  is crazy,but this page was not found';
});
//异常或者错误处理
$app->error(function($exception){
    echo '<h1>catch error:</h1>';
    echo $exception->getMessage();
});
//say/hello/hch
$app->get('/say/hello/{name}', function($name='you'){
    echo '<h1>hello '.$name.'</h1>';
});
$app->get('/', function(){
    echo '<h1>Welcome!!!</h1>';
});
//rest api
$app->get('/products', 'getProducts');
$app->post('/products/add', 'addProduct');
$app->put('/products/{id}', 'updateProduct');
$app->delete('/products/{id}', 'deleteProduct');
$app->options('/products/{id}', 'infoProduct');
$app->patch('/products/{id}', 'infoProduct');
$app->map('/repos/store/refs', 'action_product')->via(['GET', 'POST']);
$app->handle();
